<template>
  <TableToolbar>
    <template #bar-left>
      <div class="flex items-center table-title">
        <like-filled color="#ff4d4f" />
        <span class="ml-1 leading-0">版本优惠</span>
      </div>
    </template>
  </TableToolbar>
  <div class="version-wrapper flex pl-6">
    <BwVersionCard
      :selected="item.active"
      :key="index"
      v-for="(item, index) in data"
      @click="handleVersionSelected(item)"
    >
      <template #title>{{ item.title }}</template>
      <template #content>{{ item.desc }}</template>
    </BwVersionCard>
  </div>
</template>

<script lang="ts" setup>
import TableToolbar from '@/components/table-toolbar/index.vue'
import { useVModel } from '@vueuse/core'
import { LikeFilled } from '@ant-design/icons-vue'
import BwVersionCard from './BwVersionCard.vue'
import type { VersionItem } from '@/views/price-sheet/interface'

interface Props {
  versionList: VersionItem[]
}

const props = withDefaults(defineProps<Props>(), {
  versionList: () => []
})

const data = useVModel(props, 'versionList')

function handleVersionSelected(item: (typeof data.value)[number]) {
  data.value.forEach((d) => {
    d.active = false
  })

  item.active = true
}
</script>

<script lang="ts">
export default {
  name: 'BwVersion'
}
</script>

<style lang="scss" scoped>
.table-title {
  color: #ff4d4f;
  font-weight: bold;
  font-size: 22px;
}

.version-wrapper {
  display: flex;
  align-items: center;
  padding-left: 0;
}
</style>
